package yxy.game.pm2.command.plainsarena;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.PlainsArenaMessage;
import yxy.game.pm2.module.plainsarena.PlainsArenaHandle;

/** 中原擂台 中原擂台挑战记录 */
@MessageType(proto = Command.PlainsArenaRecord, classtype = PlainsArenaMessage.PlainsArenaRecordRequest.class)
public class CMD_PlainsArenaRecord extends Command<PlainsArenaMessage.PlainsArenaRecordRequest> {

	@Override
	public void execute(MessageSource messageSource, PlainsArenaMessage.PlainsArenaRecordRequest request) {
		String playerCode = messageSource.getTag();

		PlainsArenaMessage.PlainsArenaRecordResponse.Builder response = PlainsArenaMessage.PlainsArenaRecordResponse.newBuilder();

		Result result = new PlainsArenaHandle().record(playerCode, response);

		send(messageSource, response, result);
	}

	private void send(MessageSource messageSource, PlainsArenaMessage.PlainsArenaRecordResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}